<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>添加管理员</title>
</head>
<body>
<div class="box">
    <!-- /.box-header -->
    <section class="content">
    <div class="box-body">
        <form role="form">
            <div class="form-group col-md-7">
                <label>角色列表</label>
                <div style="border: 1px solid #ccc;padding: 15px 15px 0 15px;">
                    {volist name='list' id='v'}
                    <div class="form-group slide" style="margin-bottom: 5px;">
                        <label>
                            <div class="iradio_flat-green" aria-checked="false" aria-disabled="false" style="position: relative;">
                                <input type="checkbox" name="rule" value="{$v.id}" class="flat-red check1" style="position: absolute; opacity: 0;">
                                <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>
                            </div>
                            {$v.rolename}
                        </label>
                    </div>
                    {/volist}
                </div>
            </div>
            <input type="hidden" value="{$id}" id="aid">
            <div class="form-group col-md-7" >
                <div id="btn_edit" class="btn btn-info btn-flat pull-right">保存</div>
            </div>
        </form>
    </div>
    <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    $(function(){
        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass   : 'iradio_minimal-blue'
        });
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
            checkboxClass: 'icheckbox_minimal-red',
            radioClass   : 'iradio_minimal-red'
        });
        //Flat red color scheme for iCheck
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
            checkboxClass: 'icheckbox_flat-green',
            radioClass   : 'iradio_flat-green'
        });
        $('#btn_edit').click(function(){
            var _ids =[];
            $('input[name="rule"]:checked').each(function(){
                _ids.push($(this).val());
            });
            var _id = $('#aid').val();
            $.ajax({
                cache: false,
                url:'{:url("user/doAddrole")}',
                data:{ids:_ids,id:_id},
                type:'post',
                success:function(data){
                    if(data.code==0){
                        layerAlert('添加成功',function(){
                            parent.window.location.reload();
                            layerParentClose();
                        })
                    }else{
                        layerAlert('添加失败');
                    }
                },
                error:function(){
                    layerAlert('系统错误，请联系管理员');
                }
            })
        })
    })
</script>
</html>